home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / firefox / components / nsDefaultCLH.js < prev    next >
Encoding:
Text File  |  2007-04-03  |  6.4 KB  |  190 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is the Mozilla Firefox browser.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Benjamin Smedberg <benjamin@smedbergs.us>
  18.  *
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *  Daniel Glazman <daniel.glazman@disruptive-innovations.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. const nsISupports              = Components.interfaces.nsISupports;
  40.  
  41. const nsICategoryManager       = Components.interfaces.nsICategoryManager;
  42. const nsIComponentRegistrar    = Components.interfaces.nsIComponentRegistrar;
  43. const nsICommandLine           = Components.interfaces.nsICommandLine;
  44. const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
  45. const nsIFactory               = Components.interfaces.nsIFactory;
  46. const nsIModule                = Components.interfaces.nsIModule;
  47. const nsIPrefBranch            = Components.interfaces.nsIPrefBranch;
  48. const nsISupportsString        = Components.interfaces.nsISupportsString;
  49. const nsIWindowWatcher         = Components.interfaces.nsIWindowWatcher;
  50.  
  51. /**
  52.  * This file provides a generic default command-line handler.
  53.  *
  54.  * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
  55.  * with the flags specified by the pref "toolkit.defaultChromeFlags"
  56.  * or "chrome,dialog=no,all" is it is not available.
  57.  * The arguments passed to the window are the nsICommandLine instance.
  58.  *
  59.  * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
  60.  */
  61.  
  62. var nsDefaultCLH = {
  63.   /* nsISupports */
  64.  
  65.   QueryInterface : function clh_QI(iid) {
  66.     if (iid.equals(nsICommandLineHandler) ||
  67.         iid.equals(nsIFactory) ||
  68.         iid.equals(nsISupports))
  69.       return this;
  70.  
  71.     throw Components.results.NS_ERROR_NO_INTERFACE;
  72.   },
  73.  
  74.   /* nsICommandLineHandler */
  75.  
  76.   handle : function clh_handle(cmdLine) {
  77.     if (cmdLine.preventDefault)
  78.     return;
  79.  
  80.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  81.                           .getService(nsIPrefBranch);
  82.  
  83.     try {
  84.       var singletonWindowType = prefs.getCharPref("toolkit.singletonWindowType");
  85.       var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  86.                                      .getService(Components.interfaces.nsIWindowMediator);
  87.       var win = windowMediator.getMostRecentWindow(singletonWindowType);
  88.       if (win) {
  89.          win.focus();
  90.           cmdLine.preventDefault = true;
  91.           return;
  92.       }
  93.     }
  94.     catch (e) { }
  95.  
  96.     // if the pref is missing, ignore the exception 
  97.     try {
  98.       var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
  99.  
  100.       var flags = "chrome,dialog=no,all";
  101.       try {
  102.         flags = prefs.getCharPref("toolkit.defaultChromeFeatures");
  103.       }
  104.       catch (e) { }
  105.  
  106.       var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  107.                             .getService(nsIWindowWatcher);
  108.       wwatch.openWindow(null, chromeURI, "_blank",
  109.                         flags, cmdLine);
  110.     }
  111.     catch (e) { }
  112.   },
  113.  
  114.   helpInfo : "",
  115.  
  116.   /* nsIFactory */
  117.  
  118.   createInstance : function mdh_CI(outer, iid) {
  119.     if (outer != null)
  120.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  121.  
  122.     return this.QueryInterface(iid);
  123.   },
  124.  
  125.   lockFactory : function mdh_lock(lock) {
  126.     /* no-op */
  127.   }
  128. };
  129.  
  130. const clh_contractID = "@mozilla.org/toolkit/default-clh;1";
  131. const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}");
  132.  
  133. var Module = {
  134.   /* nsISupports */
  135.  
  136.   QueryInterface : function mod_QI(iid) {
  137.     if (iid.equals(nsIModule) ||
  138.         iid.equals(nsISupports))
  139.       return this;
  140.  
  141.     throw Components.results.NS_ERROR_NO_INTERFACE;
  142.   },
  143.  
  144.   /* nsIModule */
  145.  
  146.   getClassObject : function mod_gch(compMgr, cid, iid) {
  147.     if (cid.equals(clh_CID))
  148.       return nsDefaultCLH.QueryInterface(iid);
  149.  
  150.     throw components.results.NS_ERROR_FAILURE;
  151.   },
  152.  
  153.   registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  154.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  155.  
  156.     compReg.registerFactoryLocation(clh_CID,
  157.                                     "nsDefaultCLH",
  158.                                     clh_contractID,
  159.                                     fileSpec,
  160.                                     location,
  161.                                     type);
  162.  
  163.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  164.                            .getService(nsICategoryManager);
  165.  
  166.     catMan.addCategoryEntry("command-line-handler",
  167.                             "y-default",
  168.                             clh_contractID, true, true);
  169.   },
  170.  
  171.   unregisterSelf : function mod_unreg(compMgr, location, type) {
  172.     var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
  173.     compReg.unregisterFactoryLocation(clh_CID, location);
  174.  
  175.     var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  176.                            .getService(nsICategoryManager);
  177.  
  178.     catMan.deleteCategoryEntry("command-line-handler",
  179.                                "y-default");
  180.   },
  181.  
  182.   canUnload : function (compMgr) {
  183.     return true;
  184.   }
  185. };
  186.  
  187. function NSGetModule(compMgr, fileSpec) {
  188.   return Module;
  189. }
  190.